package groovy

import com.gee.spring.cloud.common.core.domain.frame.CstpWrapper
import com.gee.spring.cloud.common.core.entity.center.config.Org
import com.gee.spring.cloud.common.core.entity.center.config.OrgCenter
import com.gee.spring.cloud.data.transform.core.util.MappingUtil
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled


//需设置cstpWrapper的tid, did,bid用于确定channelHandlerConfig
static CstpWrapper toCstpHead(Org org, OrgCenter orgCenter, byte[] data){
    ByteBuf byteBuf = Unpooled.wrappedBuffer(data)
    CstpWrapper cstpWrapper = new CstpWrapper()
    cstpWrapper
            .setTid((int)MappingUtil.getSateIdentity(orgCenter.getOrgId(), byteBuf.getShortLE(1)))
            .setDid((int)MappingUtil.getDevIdentity(orgCenter.getOrgId(), byteBuf.getIntLE(7)))
            .setBid((int)MappingUtil.getFrameBid(orgCenter.getOrgId(), byteBuf.getIntLE(11)))
    ;
    byteBuf.release();
    return cstpWrapper;
}
